package com.edu.his.service.impl;

import com.edu.his.domain.Employee;
import com.edu.his.mapper.EmployeeMapper;
import com.edu.his.service.EmployeeService;
import com.edu.his.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * 描述：
 * 创建人：飘
 * 创建时间：2024/12/16
 **/
@Service
public class EmployeeServiceImpl implements EmployeeService{

    @Autowired
    private EmployeeMapper employeeMapper;


    @Override
    public R getEmployee(Employee employee) {
        //
//        String a="上午";
//        int amPM=a.equals("上午")?0:1;
        List<Employee> list=this.employeeMapper.getEmployee(employee);
        //得到上午(0)或下午(1)
        int am_pm= Calendar.getInstance().get(Calendar.AM_PM);
        //周几

        //00 10 00 10 00 10 00
        //从周日开始(00)
        //00 10 00
        int weekDay=(Calendar.getInstance().get(Calendar.DAY_OF_WEEK)-1)*2;
        List<Employee> newList=new ArrayList<>();
        //遍历集合
        for(Employee emp:list)
        {
            char index=emp.getWeekRule().charAt(weekDay+am_pm);

            if(index=='1')
            {
                newList.add(emp);
            }
        }


        return R.success(200,"查询成功",newList);
    }

    @Override
    public R selectByDepartmentId(Integer departmentId) {
        return R.success(200,"查询成功",this.employeeMapper.selectByDepartmentId(departmentId));
    }


}
